//
//  Kylin_SettingViewController.m
//  03-BuDeJie-2 TabBar设置
//
//  Created by Kylin on 16/2/4.
//  Copyright © 2016年 kylin. All rights reserved.
//

#import "Kylin_SettingViewController.h"
#import "Kylin_ClearCacheCell.h"
#import "Kylin_thirdCell.h"

@interface Kylin_SettingViewController ()

@end

static NSString * const Kylin_SettingID = @"setting";
static NSString * const Kylin_NormalID = @"normal";
static NSString * const Kylin_ThirdID = @"third";
@implementation Kylin_SettingViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"设置";
    self.view.backgroundColor = Kylin_CommonBgColor;
    
    [self.tableView registerClass:[Kylin_ClearCacheCell class] forCellReuseIdentifier:Kylin_SettingID];
    [self.tableView registerClass:[Kylin_thirdCell class] forCellReuseIdentifier:Kylin_ThirdID];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:Kylin_NormalID];
    
    self.tableView.contentInset = UIEdgeInsetsMake(Kylin_CommonMargin - 35, 0, 0, 0);

    
}



#pragma mark- 数据源

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        Kylin_ClearCacheCell *cell = [tableView dequeueReusableCellWithIdentifier:Kylin_SettingID];
        
        [cell updateStatus];
        return cell;
    }else if (indexPath.section == 1 && indexPath.row == 2){
        return [tableView dequeueReusableCellWithIdentifier:Kylin_ThirdID];
    }else{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Kylin_NormalID];
        cell.textLabel.text = [NSString stringWithFormat:@"%zd - %zd",indexPath.section,indexPath.row];
        return cell;
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    // 取消选中
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    // 只有固定是CELL才需要清除缓存
    if (indexPath.section == 0 & indexPath.row == 0) {
        // 取出当前点击的view
        Kylin_ClearCacheCell *cell = (Kylin_ClearCacheCell *) [tableView cellForRowAtIndexPath:indexPath];
        
        [cell clearCaches];
    };
   
}


@end
